package com.jxauaia.contest.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
public class AIConfigValidator implements CommandLineRunner {

    private static final Logger logger = LoggerFactory.getLogger(AIConfigValidator.class);

    @Value("${ai.spark.appid}")
    private String appId;

    @Value("${ai.spark.api-key}")
    private String apiKey;

    @Value("${ai.spark.api-secret}")
    private String apiSecret;

    @Value("${ai.spark.api-url}")
    private String apiUrl;

    @Override
    public void run(String... args) {
        logger.info("正在验证AI配置...");
        
        if (appId == null || appId.isEmpty()) {
            logger.error("AI配置错误: appid未设置或为空");
        } else {
            logger.info("AI配置 - appid: {}", appId);
        }
        
        if (apiKey == null || apiKey.isEmpty()) {
            logger.error("AI配置错误: api-key未设置或为空");
        } else {
            logger.info("AI配置 - api-key: {}", apiKey.substring(0, 4) + "****");
        }
        
        if (apiSecret == null || apiSecret.isEmpty()) {
            logger.error("AI配置错误: api-secret未设置或为空");
        } else {
            logger.info("AI配置 - api-secret: {}****", apiSecret.substring(0, 4));
        }
        
        logger.info("AI配置 - api-url: {}", apiUrl);
    }
}